﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebBrowserTest.Utility;
using HtmlAgilityPack;
namespace WebBrowserTest.DetailsAnalyzing
{
    public class GoogleBrowseAnalyzer 
    {
        private const string _googleQueryUrl = "http://www.google.pl/search?q={0}&ie=utf-8";
        private HtmlDocument _htmlDoc = new HtmlDocument();
        private string _keyword;
        private GoogleBrowseAnalyzer()
        {
        }

        public GoogleBrowseAnalyzer(string keyword)
        {
            _keyword = keyword;
        }
        public List<string> GetSearchResultDomains()
        {
            List<string> domains = new List<string>();
            string html = Utils.getPageHtmlString(string.Format(_googleQueryUrl, _keyword));
            _htmlDoc.LoadHtml(html);
            var domainNodes = _htmlDoc.DocumentNode.SelectNodes("//a[@class='l']");
            foreach (HtmlNode domainNode in domainNodes)
            {
                domains.Add(domainNode.Attributes["href"].Value);
            }

            
            return domains.Take(2).ToList();
        }
    }
}
